//判断姓名是否为空
function judgeName() {
    var name=document.getElementById("name");
    var name_correct=document.getElementById("name_correct");
    var tip=document.getElementById("name_tip");
    var note=tip.parentNode;
    if(name.value.length>0){
        note.className="note correct"
        name_correct.className="";
        tip.className="hidden";
        return true;
    }else{
        note.className="note error";
        name_correct.className="hidden";
        tip.className="";
        return false;
    }

}

//判断密码格式
function judgePassword1() {
    var pwd1=document.getElementById("password1");
    var reg=/^.{6,25}$/    //密码长度6-25
    var tip=document.getElementById("password1_tip");
    var password1_error=document.getElementById("password1_error");
    var password1_correct=document.getElementById("password1_correct");
    var note=document.getElementById("password1_tip").parentNode;
    if(reg.test(pwd1.value)){
        note.className="note correct"
        password1_correct.className="";
        password1_error.className="hidden";
        tip.className="hidden";
        return true;
    }else{
        note.className="note error"
        password1_correct.className="hidden";
        password1_error.className="";
        tip.className="";
        return false;
    }
}
//判断2次密码是否一致
function judgePassword2() {
    var pwd2=document.getElementById("password2");
    var pwd1=document.getElementById("password1");
    var password2_correct=document.getElementById("password2_correct");
    var password2_error=document.getElementById("password2_error");
    document.getElementById("password2_tip").className="hidden";
    var note=document.getElementById("password2_tip").parentNode;
    if(pwd2.value==pwd1.value&&pwd2.value.length>0){
        note.className="note correct";
        password2_correct.className="";
        password2_error.className="hidden";
        return true;
    }else{
        note.className="note error";
        password2_correct.className="hidden";
        password2_error.className="";
        return false;
    }
}
//判断手机号格式
function judeTel() {
    var tel=document.getElementById("tel");
    var tel_correct=document.getElementById("tel_correct");
    var tel_error=document.getElementById("tel_error");
    var tip=document.getElementById("tel_tip");
    var note=tip.parentNode;
    var reg=/^1[35874]\d{9}$/
    tip.className="hidden";
    if(reg.test(tel.value)){
        note.className="note correct";
        tel_correct.className="";
        tel_error.className="hidden";
        return true;
    }else{
        note.className="note error";
        tel_correct.className="hidden";
        tel_error.className="";
        return false;
    }
}
//判断邮箱格式
function judgeEmail() {
    var email=document.getElementById("email");
    var email_correct=document.getElementById("email_correct");
    var email_error=document.getElementById("email_error");
    var tip=document.getElementById("email_tip");
    var note=tip.parentNode;
    var reg=/^[0-9a-zA-Z-_]+@[0-9a-zA-Z-_]+\.\w+$/;
    tip.className="hidden";
    if(reg.test(email.value)){
        note.className="note correct";
        email_correct.className="";
        email_error.className="hidden";
        return true;
    }else{
        note.className="note error";
        email_correct.className="hidden";
        email_error.className="";
        return false;
    }
}
//判断职务
function judgeWork() {
    var work=document.getElementById("work");
    var work_correct=document.getElementById("work_correct");
    var work_error=document.getElementById("work_error");
    var tip=document.getElementById("work_tip");
    var note=tip.parentNode;
    tip.className="hidden";
    if(work.value.length>0){
        note.className="note correct";
        work_correct.className=""
        work_error.className="hidden";
        return true;
    }else{
        note.className="note error";
        work_correct.className="hidden"
        work_error.className="";
        return false;
    }
}
//判断学校是否为空
function judgeSchool() {
    var school=document.getElementById("school");
    var school_error=document.getElementById("school_error");
    if(school.value.length>0){
        school_error.className="hidden";
        return true;
    }else{
        school_error.className="note error"
        return false;
    }
}
//判断协议
function judgeAgreement() {
    var check=document.getElementById("check");
    var check_true=document.getElementById("check_true");
    if(check.checked){
        check_true.className="hidden";
        return true;
    }else{
        check_true.className="note error"
        return false;
    }
}
function judge() {
    return judgeName()&&judgePassword1()&&judgePassword2()&&judeTel()&&judgeEmail()&&judgeWork()&&judgeSchool()&&judgeAgreement();
}

$(function () {
    var citys=["北京市","天津市","四川省","上海市"]
    var cityCount=citys.length;
    var html1="";
    var defaultArea="";
    var areas=[
        ["东城区","西城区","朝阳区","丰台区"],
        ["和平区","河东区","河西区","南开区"],
        ["成都市","广元市","绵阳市","德阳市"],
        ["黄浦区","卢湾区","徐汇区","长宁区"]
    ]
    //初始化
    for(var i=0;i<cityCount;i++){
        html1+="<option value='"+citys[i]+"'>"+citys[i]+"</option>";
    }
    for(var i=0;i<areas[0].length;i++){
        defaultArea+="<option value='"+areas[0][i]+"'>"+areas[0][i]+"</option>";
    }
    $("#city").html(html1);
    $("#area").html(defaultArea);

    //省份改变时
    $("#city").change(function () {
        var index=$("#city option:selected").index();
        var html2="";
        for(var i=0;i<areas[index].length;i++){
            html2+="<option value='"+areas[0][i]+"'>"+areas[index][i]+"</option>"
        }
        $("#area").html(html2);
    })

})



